package com.example.myesstudy.service.impl;

import com.example.myesstudy.dao.BookDao;
import com.example.myesstudy.pojo.ReadBook;
import com.example.myesstudy.repository.BookRepository;
import com.example.myesstudy.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BookServiceImpl implements BookService {


    @Autowired
    private BookDao bookDao;

    @Autowired
    private BookRepository bookRepository;


    /**
     * 测试 将 elk数据库的read_book_pd 表中数据插入到es 中去
     */
    @Override
    public void insertEs() {

        long startTime = System.currentTimeMillis();


        int count = bookDao.queryCount();


        Map<String, Object> params = new HashMap<>();


        params.put("offset", 0);
        params.put("sizes", 100);
        List<ReadBook> list = bookDao.queryFenye(params);
        bookRepository.saveAll(list);
 /*       list.stream().forEach(n -> {
            ReadBook b = bookRepository.save(n);
        });*/


        long endTime = System.currentTimeMillis();

        System.out.println(count + " 条数据,共耗时 " + (endTime - startTime));


    }

}
